import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import * as moment from 'moment';

@Component({
    selector: 'app-dd-overview',
    templateUrl: './dd-overview.component.html',
    styleUrls: ['./dd-overview.component.scss']
})
export class DdOverviewComponent implements OnInit {
    currentDate = new Date();
    serverUrl = (window as any).environment.reportUrl;
    iframeSrc: SafeResourceUrl;
    loading = true;
    constructor(private sanitizer: DomSanitizer) {
    }

    ngOnInit(): void {
        this.queryInfo();
    }

    queryInfo(): void {
        this.loading = true;
        const date = moment(this.currentDate).format('YYYY-MM-DD');
        const token = localStorage.token;
        const link = `${this.serverUrl}preview?_u=wrs:每日调度报表.ureport.xml&_t=3,6&ct_createtime=${date}&token=${token}`;
        this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link);
    }

    iframeOnLoad(): void {
        this.loading = false;
    }
}
